<template>
    <mescroll-uni
        ref="mescrollRef"
        @init="mescrollInit"
        :height="height"
        :down="downOption"
        @down="downRefresh"
        :up="upOption"
        @up="getData">
        <easy-item-title :title="`共${allLength}家客户`"></easy-item-title>
        <customer-list-item
            v-for="(item, index) in datas"
            :item="item"
            :index="index"
            :key="index"
            :selectType="selectType"></customer-list-item>
        <view class="list-footer"></view>
    </mescroll-uni>
</template>

<script>
import { mapGetters } from "vuex"
import customerListItem from "@/components/customer/customer-list-item.vue"
import easyItemTitle from "@/components/easy/easy-item-title.vue"
import { GetGuideStorePage } from "@/service/api/store.js"
export default {
    components: {
        customerListItem,
        easyItemTitle,
    },
    props: {
        height: {
            type: String,
            default: "300px",
        },
        type: {
            type: Number,
            default: 1,
        },
        selectType: {
            type: String,
            default: "",
        },
    },
    data() {
        return {
            datas: [],
            allLength: 0,
            data: [],
            productList: [],
            downOption: {
                use: true,
            },
            isLoaded: false,
            param: {
                keyword: "",
                provinceId: 0,
                cityId: 0,
                regionId: 0,
                streetId: 0,
                dealerGrades: "",
                isFilterWorker: true,
                customerType: 3,
            },
        }
    },
    computed: {
        ...mapGetters(["getUpClientView"]),
    },
    watch: {
        //监听更新
        getUpClientView(e) {
            this.downRefresh()
        },
    },
    mounted() {
        this.refresh()
    },
    methods: {
        //获取列表数据
        getData(page) {
            if (this.selectType) {
                this.param.status = 1
            }
            let path = "?pageIndex=" + page.num + "&pageSize=" + page.size
            GetGuideStorePage(this.param, path).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                    this.allLength = res.RecordAmout
                    this.isLoaded = true
                } else {
                    this.mescroll.endBySize(0, 0)
                    this.easyToast(res.Msg)
                }
            })
        },
        //刷新
        refresh(param = null) {
            if (param) {
                this.param = param
            }
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
    },
}
</script>

<style lang="scss"></style>
